package creational.prototype;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class DeepClone implements Cloneable{
    String name;
    List<ShadowClone> childList;
    public DeepClone(String _name){
        this.name = _name;
        childList = new ArrayList<>();
        for(int i=0;i<10;i++){
            childList.add(new ShadowClone(""+i));
        }
    }

    @Override
    public DeepClone clone(){
        DeepClone parent;
        try{
            parent = (DeepClone)super.clone();
            parent.childList = childList.stream().map(ShadowClone::clone).collect(Collectors.toList());
            return parent;
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return null;
    }

    public void setChildList(List<ShadowClone> list){
        this.childList = list;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<ShadowClone> getChildList() {
        return childList;
    }
}
